
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>发送招聘</title>
    <script type="text/javascript" src="../../static/common/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="../../static/common/jquery/jquery-1.11.1.min.js"></script>
    <link rel="stylesheet" href="../../static/common/layui/css/layui.css">
    <script src="../../static/common/axios.min.js"></script>
    <script src="../../static/common/vue.min.js"></script>
</head>
<body>
<div style="margin: 15px;">
    <form class="layui-form" action="">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>招聘信息</legend>
        </fieldset>
        <form class="layui-form" >
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input name="title" class="layui-input" >
                </div>
                <label class="layui-form-label">招聘类别</label>
                <div class="layui-input-inline">
                    <select name="type" lay-filter="type"  lay-search>
                        <option value="">选择招聘类别</option>
                        <option value="1">实习招聘</option>
                        <option value="2">就业招聘</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">岗位类别</label>
                <div class="layui-input-inline">
                    <select name="positiontype" lay-filter="positionType"  lay-search>
                        <option value="">选择岗位</option>
                    </select>
                </div>
                <label class="layui-form-label">选择公司</label>
                <div class="layui-input-inline">
                    <select name="orgid" lay-filter="company"  lay-search>
                        <option value="">选择公司</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作城市</label>
                <div class="layui-input-inline">
                    <input name="workingcity" class="layui-input" >
                </div>

                <label class="layui-form-label">起薪</label>
                <div class="layui-input-inline">
                    <input name="salaryllimit" class="layui-input" lay-verify="numOfSalary">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作内容</label>
                <div class="layui-input-block">
                    <textarea id="ta_ckeditor" class="ckeditor my-math" cols="20" rows="2" style="overflow:auto"></textarea>
                    <script type="text/javascript">CKEDITOR.replace('ta_ckeditor');</script>
                </div>
                <%--<textarea id="ta_ckeditor" class="ckeditor my-math" cols="20" rows="2" style="overflow:auto"></textarea>--%>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">工作环境照片</label>
                <div class="layui-input-block">
                    <img src="" id="showWorkingPic" style="height: 100px;width: 100px">
                    <input type="file" name="fileUp" id="workingpic" class="layui-upload-file">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">其他说明</label>
                <div class="layui-input-block">
                    <input name="comment" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">招聘人数</label>
                <div class="layui-input-inline">
                    <input name="recruitnum" class="layui-input" lay-verify="numOfPerson">
                </div>

                <label class="layui-form-label">联系人</label>
                <div class="layui-input-inline">
                    <input name="recruitnum" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input name="recruitnum" class="layui-input" >
                </div>
                <label class="layui-form-label">联系邮箱</label>
                <div class="layui-input-inline">
                    <input name="recruitnum" class="layui-input" >
                </div>
            </div>
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="edit">提交</button>
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="save">暂存</button>
                <button type="submit" class="layui-btn" onclick="window.history.go(-1);">返回</button>
            </div>
        </form>
    </form>
</div>
<script src="../../static/common/layui/layui.js"></script>
<script>
    var userId = ${sessionScope.currentUser.getId()};
    var admin = {
        school:{}
    };
    var positionTypes = [];//所有岗位信息
    var company = [];

    axios.get('/magfacultyinfo/findOne/'+userId)
        .then(function (response) {
            console.log(response.data);
            admin = response.data.data;
        })
        .catch(function (msg) {
            console.log(msg);
        })
</script>
<script>
    var myDate = new Date();
    layui.use(['form','jquery','layer', 'upload'],function() {
        var form = layui.form(),
            $ = layui.jquery;
        var image = {};

        var workingpic;
        var da = new Date();
        var myDate=da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate() + " " + da.getHours() + ":" + da.getMinutes() + ":" + da.getSeconds();

        form.on('submit(edit)', function (data) {
            console.log(data.field);
            data.field.publisherid = ${sessionScope.currentUser.getId()};
            data.field.job=CKEDITOR.instances.ta_ckeditor.document.getBody().getText();
            data.field.publishdate=myDate;
            data.field.state=2;
            data.field.workingpic=workingpic;
            $.ajax({
                url:'/recruitInfo/add'
                ,type:'post'
                ,contentType : "application/json; charset=utf-8"
                ,data:JSON.stringify(data.field)
                ,dataType:'json'
                ,success:function (response) {
                    layer.msg(response.message,function () {
                        window.history.go(-1);
//                        parent.tab.deleteTab(parent.tab.getCurrentTabId());
                    });
                }
            });
            return false;
        });
        form.on('submit(save)', function (data) {
            console.log(data.field);
            data.field.publisherid = ${sessionScope.currentUser.getId()};
            data.field.job=CKEDITOR.instances.ta_ckeditor.getData();
            data.field.publishdate=myDate;
            data.field.state=1;
            data.field.workingpic=workingpic;
            $.ajax({
                url:'/recruitInfo/add'
                ,type:'post'
                ,contentType : "application/json; charset=utf-8"
                ,data:JSON.stringify(data.field)
                ,dataType:'json'
                ,success:function (response) {
                    layer.msg(response.message,function () {
                        window.history.go(-1);
                    });
                }
            });
            return false;
        });

        form.verify({
            numOfSalary:function (data) {
                if(isNaN(data)&&data!=''){
                    layer.msg("起薪必须为数字",{icon:2,time:1000});
                }
            },
            numOfPerson:function (data) {
                if(isNaN(data)&&data!=''){
                    layer.msg("招聘人数必须为数字",{icon:2,time:1000});
                }
            }
        });

        var vm = new Vue({
            el: '#Vue',
            data: {
                show: true,
                recruitinfo: {
                    publisherid: userId
                }
            },
        });

        layui.upload({
            url: '/upload/workingpic',
            success: function (response) {
                image.path = response.data;
                image.description = "工作环境";
                image.isencrypted = 2;//需要加密
                axios.post("/image/add", image)
                    .then(function (response) {
                        console.log(response.data);
                        workingpic = response.data.data;
                        axios.get("/image/find/" + response.data.data)
                            .then(function (response) {
                                $('#showWorkingPic').attr('src', response.data.data);
                            })
                            .catch(function (response) {
                                console.log(response);
                            });
                    })
                    .catch(function (response) {
                        console.log(response);
                    })

            },
            before: function () {
                console.log('工作环境上传中');
            }
        });

        //获取全部岗位信息
        axios.get('/PositionType/findBatchBySchoolId/'+admin.school.id)
            .then(function (response) {
                console.log(response)
                for (var i = 0; i < response.data.data.length; i++) {
                    positionTypes[response.data.data[i].id] = response.data.data[i].posname;
                }
                console.log(positionTypes);
                //有效岗位类别
                var validPositionTypes = response.data.data;
                var html = '';
                for (var i in validPositionTypes) {
                    html += '<option value=' + validPositionTypes[i].id + '>' + validPositionTypes[i].posname + '</option>';
                }
                $('select[name=positiontype]').append(html);
                form.render('select');
            })
            .catch(function (response) {
                console.log(response);
            });
        axios.post('/orginfo/findByCondition',{state:3})
            .then(function (response) {
                console.log(response.data);
                for (var i = 0; i < response.data.data.length; i++) {
                    company[response.data.data[i].id] = response.data.data[i].fullname;
                }
                var companyes = response.data.data;
                var html = '';
                for (var i in companyes) {
                    html += '<option value=' + companyes[i].id + '>' + companyes[i].fullname + '</option>';
                }
                $('select[name=orgid]').append(html);
                form.render('select');
            })
            .catch(function (response) {
                console.log(response);
            });
        //首先渲染
        form.render();
    })
</script>

</body>
</html>
